<?php
class myfunction{
	function str_to($str){
		$str=str_replace("","&nbsp;","$str");
		$str=str_replace("<","&lt","$str");
		$str=str_replace("","&gt","$str");
		$str=nl2br($str);
		return $str;
	}
	function note_num(){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info ";
		$rst=$aa->excu($query);
		$note_num=mysql_num_rows($rst);
		return $note_num;
	}
	function user_num(){
		$aa=new mysql;
		$aa->link("");
		$query="select * from user_info ";
		$rst=$aa->excu($query);
		$user_num=mysql_num_rows($rst);
		return $user_num;
	}
	function last_user_name(){
		$aa=new mysql;
		$aa->link("");
		$query="select * from user_info order by id desc limit 0,1";
		$rst=$aa->excu($query);
		$user_info=mysql_fetch_array($rst);
		return $user_info["user_name"];
	}
	function son_module_idtonum($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where module_id='$son_module_id' and up_id='0'";
		$rst=$aa->excu($query);
		$num=mysql_num_rows($rst);
		return $num;
	}
	function son_module_idtonum2($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where module_id='$son_module_id' ";
		$rst=$aa->excu($query);
		$num2=mysql_num_rows($rst);
		return $num2;
	}
	function son_module_idtolast_note($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where module_id='$son_module_id' order by time desc limit 0,1";
		$rst=$aa->excu($query);
		$note_info=mysql_fetch_array($rst);
		echo $note_info["title"];
		echo "<br>";
		echo $note_info["time"]."&nbsp;&nbsp;&nbsp;".$note_info["user_name"];
	}
	function son_module_idtouser_name($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from son_module_info where id='$son_module_id' ";
		$rst=$aa->excu($query);
		$son_info=mysql_fetch_array($rst);
		if ($son_info["user_name"]==""){
			return 版主暂缺;
		}else{
			return  $son_info["user_name"];
		}
	}
	function son_module_idtofarther_name($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from son_module_info where id='$son_module_id'";
		$rst=$aa->excu($query);
		$son_info=mysql_fetch_array($rst);
		$query2="select * from father_module_info where id=" . $son_info['farther_id'];
		$rest=$aa->excu($query2);
		$father_info=mysql_fetch_array($rest);
		return $father_info["module_name"];
	}
	function son_module_idtomodule_name($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from son_module_info where id='$son_module_id' ";
		$rst=$aa->excu($query);
		$son_info=mysql_fetch_array($rst);
		return $son_info["module_name"];
	}
	function page($query,$add,$page_id,$num_per_page){
		$aa=new mysql;
		$aa->link("");
		$rst=$aa->excu($query);
		$num=mysql_num_rows($rst);
		if($num==0){
			echo "没有查到相关记录或回复<br>";
		}
		$page_id=$_GET["page_id"];
		if($page_id==""){
			$page_id=1;
		}
		$page_id = $page_id==0?1:$page_id;
		$page_num=ceil($num/$num_per_page);

		$page_up=$page_id-1;
		$page_down=$page_id+1;
		if($page_id==1){
			echo "<a href=?".$add."page_id=$page_down>下一页</a>&nbsp;第".$page_id."页，共".$page_num."页";
			}else if($page_id==$page_num){
			echo "<a href=?".$add."page_id=$page_up>上一页</a>&nbsp;第".$page_id."页，共".$page_num."页";
			}else{
			echo "<a href=?".$add."page_id=$page_up>上一页</a>&nbsp;第".$page_id."页&nbsp;<a href=?".$add."page_id=$page_down>下一页</a>&nbsp;共".$page_num."页";
			}
			$begin=$num_per_page * ($page_id-1);
                         $query .= " limit $begin,$num_per_page";
                         return $query;
      }
      function note_idtotimes($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where id='$note_id' ";
		$rst=$aa->excu($query);
		$note=mysql_fetch_array($rst);
		return $note["times"];
	}
	function note_idtotitle($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where id='$note_id' ";
		$rst=$aa->excu($query);
		$note=mysql_fetch_array($rst);
		return $note["title"];
	}
	function note_idtouser_name($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where id='$note_id' ";
		$rst=$aa->excu($query);
		$note=mysql_fetch_array($rst);
		return $note["user_name"];
	}
	function note_idtonum($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where up_id='$note_id' ";
		$rst=$aa->excu($query);
		$nums=mysql_num_rows($rst);
		return $nums+1;
	}
	function note_idtolast_time($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where up_id='$note_id' order by time limit 0,1 ";
		$rst=$aa->excu($query);
		$note=mysql_fetch_array($rst);
		return $note["time"];
	}
	function note_idtolast_user($note_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from note_info where up_id='$note_id' order by time limit 0,1";
		$rst=$aa->excu($query);
		$note=mysql_fetch_array($rst);
		return $note["user_name"];
	}
	function son_module_list($son_module_id){
		$aa=new mysql;
		$aa->link("");
		$query="select * from father_module_info order by id";
		$rest=$aa->excu($query);
		echo "<select name=module_id>";
		while($farther_module=mysql_fetch_array($rest)){
			echo "<option value=>".$farther_module["module_name"]."</option>";
            $query="select * from son_module_info where farther_id='$farther_module[id]' order by id";
            $rst=$aa->excu($query);
            while($son_module=mysql_fetch_array($rst)){
            	echo "&nbsp;<option value=".$son_module["id"].">&nbsp;".$son_module["module_name"]."</option>";
             }
		   }
		echo "</select>";
      }
}
              function farther_module_list($farther_module_id){
		$aa=new mysql;
		$aa->link("");
		echo "<select name=farther_module_id>";
		if($farther_module_id==""){
                    echo "<option selected>请选择....</option>";
                }  else {
                     $query="select * from father_module_info where id='$farther_module_id' ";
                     $rst=$aa->excu($query);
                     $farther_module=mysql_fetch_array($rst);
                     echo "<option value=".$farther_module["id"].">".$farther_module["module_name"]."</option>";
                }
                $query="select * from father_module_info order by id";
		$rst=$aa->excu($query);
                while($farther_module=mysql_fetch_array($rst)){
                     echo "<option value=".$farther_module["id"].">".$farther_module["module_name"]."</option>";
                }
                echo "</select>";
}
function jsDo($msg,$do='')    {  //show the warning and execute some actions
  echo '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" />';
  echo '<script type="text/javascript">alert("'. $msg . '");'. $do . ';</script>';
  echo '</head><body></body></html>';
}

function jsAlert($msg)    {   //show the warning and do nothing
    jsDo($msg);
}

function pr($arr,$exit=true)   {   //print the variables in array
    echo '<pre>';
    print_r(is_array($arr) ? $arr : array('Not Array' => $arr));
    echo '</pre>';
    if($exit)   {
        exit;
    }
}
?>